//
//  RNTUtils.m
//  rzc_app
//
//  Created by 孙磊 on 2019/8/6.
//  Copyright © 2019 Facebook. All rights reserved.
//

#import "RNTUtils.h"
#import <React/RCTUIManager.h>
#import "RCTSinglelineTextInputView.h"

#import <Bugly/Bugly.h>

//#import "IQKeyboardManager.h"
//#import "IQUIView+IQKeyboardToolbar.h"
//#import "IQUITextFieldView+Additions.h"

@implementation RNTUtils

- (instancetype)init {
  return self;
}
@synthesize bridge = _bridge;
//除了实现RCTBridgeModule协议外，类还需要包含RCT_EXPORT_MODULE()宏。这个宏可以添加
//一个参数用来指定在JavaScript中访问这个模块的名字
//通常不指定名字，默认使用Objective-C类的名字
RCT_EXPORT_MODULE();
- (dispatch_queue_t)methodQueue
{
  return dispatch_get_main_queue();
}

+ (BOOL)requiresMainQueueSetup
{
  return YES;
}
RCT_EXPORT_METHOD(setUserIdentifier:(nonnull NSString *)userId tag:(NSUInteger)tag)
{
  if ([userId isEqualToString:@""]) {
    [Bugly setUserIdentifier:@"unlogin"];
  } else {
    [Bugly setUserIdentifier:userId];
  }
  [Bugly setTag:tag];
}

RCT_EXPORT_METHOD(setTextFiledByTag:(nonnull NSNumber *)reactTag){
// RCTUIManager *uiManager = _bridge.uiManager;
//  __weak typeof(self) weakSelf = self;
//  dispatch_async(uiManager.methodQueue, ^{
//    [uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *,UIView *> *viewRegistry) {
//      UIView *view = viewRegistry[reactTag];
//      if ([view isKindOfClass:[RCTSinglelineTextInputView class]]) {
//        RCTSinglelineTextInputView *textField = (RCTSinglelineTextInputView *)view;
//        IQBarButtonItem *doneBarButton = textField.keyboardToolbar.doneBarButton;
//        [textField.keyboardToolbar.previousBarButton setTarget:weakSelf action:@selector(doneAction:)];
//        [textField.keyboardToolbar.nextBarButton setTarget:weakSelf action:@selector(doneAction:)];
//        [doneBarButton setTarget:weakSelf action:@selector(doneAction:)];
//      }
//    }];
//  });
}
-(void)doneAction:(UITextField*)textField
{
    NSLog(@"%@",NSStringFromSelector(_cmd));
}
@end
